from fastapi import FastAPI
from pydantic import BaseModel
from typing import List, Optional
from models.price_predictor import PricePredictor

app = FastAPI()

class PredictRequest(BaseModel):
    features: dict
    city_level: Optional[int] = None
    session: Optional[str] = None
    user_tags: Optional[List[str]] = []
    movie_tags: Optional[List[str]] = []

@app.post("/predict")
def predict(req: PredictRequest):
    price = PricePredictor(
        feature_dict=req.features,
        city_level=req.city_level,
        session=req.session,
        user_tags=req.user_tags,
        movie_tags=req.movie_tags
    )
    return {"predicted_price": round(price, 2)}
